package com.kitty.game.task.service.targetHandler;

import com.kitty.game.task.model.product.TaskTargetType;
import com.kitty.game.task.model.product.targetparam.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 任务目标的辅助类
 */
public enum TaskTargetHelper {
    INSTANCE;

    private static Map<TaskTargetType, TaskTargetHandler> handlers = new HashMap<TaskTargetType, TaskTargetHandler>();
    /**任务目标类型对应的任务目标参数类*/
    private static Map<TaskTargetType, Class> params = new HashMap<TaskTargetType, Class>();

    private void registerHandler(TaskTargetType taskTargetType, TaskTargetHandler taskTargetHandler) {
        handlers.put(taskTargetType, taskTargetHandler);
    }

    public TaskTargetHandler getTargetHandler(TaskTargetType taskTargetType) {
        return handlers.get(taskTargetType);
    }

    public Class getTargetParamClass(TaskTargetType taskTargetType) {
        return params.get(taskTargetType);
    }

    /**初始化所有的任务目标类型对应的处理器*/
    public void initialize() {
        add(TaskTargetType.TALK, TalkTargetParam.class, new TalkTargetHandler());
        add(TaskTargetType.ON_EQUIP, OnEquipTargetParam.class, new OnEquipTargetHandler());
        add(TaskTargetType.FETCH_PET, FetchPetTargetParam.class, new FetchPetTargetHandler());
        add(TaskTargetType.FIGHT_WIN, FightWinTargetParam.class, new FightWinTargetHandler());
        add(TaskTargetType.STUDY, StudyTargetParam.class, new StudyTargetHandler());
        add(TaskTargetType.STUDY_SKILL, StudySkillTargetParam.class, new StudySkillTargetHandler());
        add(TaskTargetType.CALL_GUARD, CallGuardTargetParam.class, new CallGuardTargetHandler());
        add(TaskTargetType.ROLE_LEVEL_UP, RoleLevelUpTargetParam.class, new RoleLevelUpTargetHandler());
        add(TaskTargetType.GATHER, GatherTargetParam.class, new GatherTargetHandler());
        add(TaskTargetType.DONATE, DonateTargetParam.class, new DonateTargetHandler());
        add(TaskTargetType.CLICK_SUBMIT, ClickSubmitTargetParam.class, new ClickSubmitTargetHandler());

        add(TaskTargetType.START_YA_BIAO, YaBiaoTargetParam.class, new YaBiaoTargetHandler());
    }

    private void add(TaskTargetType taskTargetType, Class clazz, TaskTargetHandler taskTargetHandler) {
        params.put(taskTargetType, clazz);
        registerHandler(taskTargetType, taskTargetHandler);
    }

    static  {
        /**初始化*/
        INSTANCE.initialize();
    }
}
